package com.ftg.learn.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * filter token全拦截
 * @author 布衣
 */
@Data
@ApiModel("前后台交互统一封装类")
@NoArgsConstructor
@AllArgsConstructor
public class R<T> {

    @ApiModelProperty("状态码,200表示成功")
    private Integer code;
    @ApiModelProperty("提示信息")
    private String msg;
    @ApiModelProperty("影响数据")
    private T data;

    public static <T> R<T> ok() {
        return new R<T>(200, "操作成功", null);
    }

    public static <T> R<T> failure() {
        return new R<T>(500, "操作失败", null);
    }

    public static <T> R<T> ok(T data) {
        return new R<T>(200, "操作成功", data);
    }

    public static <T> R<T> failure(String msg) {
        return new R<T>(500, msg, null);
    }

    public static <T> R<T> build(Integer code,String msg,T Data) {
        return new R<T>(code, msg, Data);
    }

}
